/**
 * Author@ Cheng Feitian
 * Date: 2021-4-8
 * Description: 模板的局限性:
 * 模板不是万能的，有些特定数据类型，需要用具体化方式做特殊实现
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;

class Person
{
public:
    string m_Name;
    int m_Age;

    Person(string name, int age)
    {
        m_Name = name;
        m_Age = age;
    }
};

template <typename T>
bool myCompare(T &a, T &b)
{
    if (a == b)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//利用具体化Person的版本实现代码，具体化优先调用
template <>
bool myCompare(Person &p1, Person &p2)
{
    if (p1.m_Name == p2.m_Name && p1.m_Age == p2.m_Age)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void test01()
{
    int a = 10;
    int b = 20;

    bool ret = myCompare(a, b);

    if (ret)
    {
        cout << "a == b" << endl;
    }
    else
    {
        cout << "a != b" << endl;
    }
}

void test02()
{
    Person p1("张三", 10);
    Person p2("李四", 10);

    bool ret = myCompare(p1, p2);
    if (ret)
    {
        cout << "p1 == p2" << endl;
    }
    else
    {
        cout << "P1 != P2" << endl;
    }
}

int main()
{
    // test01();
    test02();
    return 0;
}
